require.config({
	paths : {
		"jquery" : "jquery",
		"cookie" : "cookie",
		"common" : "common"
	}
})

require(["jquery","cookie","common"],function($,cookie,common){
	$("#header").load("head.html",function(){common.fn();});
	$("#footer").load("foot.html",function(){common.fn();});
	
 	$(".login_verify input").val("");/*验证码归0*/
 	var $sjs = "";
 	for(var $i = 0;$i < 4;$i ++){
		var $s = Math.round(Math.random() * 3) % 3;
		if($s == 0){
			$sjs += String.fromCharCode((Math.round(Math.random() * 10) % 10) + 48);
		}else if($s == 1){
			$sjs += String.fromCharCode((Math.round(Math.random() * 26) % 26) + 65);
		}else{
			$sjs += String.fromCharCode((Math.round(Math.random() * 26) % 26) + 97);
		}
	}
 	$(".login_verify a div").text($sjs);/*生成验证码*/
	$(".login_verify a").click(function(){/*点击验证码*/
		$sjs = "";
		for(var $i = 0;$i < 4;$i ++){
			var $s = Math.round(Math.random() * 3) % 3;
			if($s == 0){
				$sjs += String.fromCharCode((Math.round(Math.random() * 10) % 10) + 48);
			}else if($s == 1){
				$sjs += String.fromCharCode((Math.round(Math.random() * 26) % 26) + 65);
			}else{
				$sjs += String.fromCharCode((Math.round(Math.random() * 26) % 26) + 97);
			}
		}
		$(".login_verify a div").text($sjs);/*生成验证码*/
	});
 	
 	var $users = getCookie("registerUsers") ? getCookie("registerUsers") : "";
	//将字符串转为对象
	$users = convertStrToObj($users);
	$(".login_sub").click(function(){/*验证登录*/
		if($(".login_verify input").val() != $sjs){
			alert("验证码错误")
		}else{
			if($users[$(".login_name").val()] == $(".login_lock").val()){
				//登录成功
				console.log("登录成功!");
				setCookie("active_user",$(".login_name").val());
				location.href = "index.html";
			}else{
				//登录失败
				alert("用户名和密码不匹配，请确认后重试！");
			}
		}	
	});
})
